/**
 * 游戏基础的精灵类
 */
export default class Sprite {
  constructor(img = null, x = 0, y = 0, width = 0, height = 0, visible = true) {
    this.img = img;
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
    this.visible = visible;
  }

  /**
   * 将精灵图绘制在canvas上
   */
  drawToCanvas(ctx) {
    ctx.drawImage(this.img, 0, 0, this.img.width, this.img.height, this.x, this.y, this.width, this.height);
  }

  addX(value) {
    this.x += value;
  }

  addY(value) {
    this.y += value;
  }

  moveTo(x, y) {
    this.x = x;
    this.y = y;
  }

  destory() {
    this.img = null;
  }

}
